<template>
	<view class="back">
		<view style="width: 100vw;height: 100vh;background: #fff;margin-top: 30rpx;border-radius: 70rpx 70rpx 0rpx 0rpx;padding-bottom:5vh;">
		<view style="height: 4vh;">

		</view>
		<u-popup :show="insert" @close="close" mode="center" @open="open">
						            <view style="width:600rpx;height:400rpx;padding: 20rpx;">
										<view style="float: left;">
						                <view style="margin-top: 20rpx;width: 600rpx;">
						                	训练次数：
						                </view>
						                <view style="float: left;margin-top: 20rpx;">
						                	<input type="text" v-model="item.actionCount"
						                		style="width: 120px;height: 30px; background-color: rgb(246, 245, 245);border-radius :20rpx;text-align: center;"
						                		>
						                </view>
										</view>
										<view style="float: left;">
										<view style="margin-top: 20rpx;width: 600rpx;">
											训练重量：
										</view>
										<view style="float: left;margin-top: 20rpx;">
											<input type="text" v-model="item.equipmentWeight"
												style="width: 120px;height: 30px; background-color: rgb(246, 245, 245);border-radius :20rpx;text-align: center;"
												>
										</view>
										<view style="height: 35rpx;float: right;margin-top: 20rpx;">
											<view style="float: right;color:#4089ff;margin-right: 40rpx;" @click="submits">添加</view>
										</view>
										</view>
		<!-- 								<view style="margin-top: 20rpx;float: left;width: 100%;">
											已添加动作：
										</view>
										<view style="margin-top: 20rpx;float: left;width: 100%; "  v-for="(item, index) in planFrom.planActionArray" :key="index">
											<view style="float: left;">{{item.fitnessActionName}}</view>
											<view style="float: right;color:red" @click="handleDeletess(index)">删除</view>
										</view> -->
										<!-- <view style="margin-top: 20rpx;float: left;width: 100%;">
											已添加课程：
										</view>
										<view style="margin-top: 20rpx;float: left;width: 100%; " v-for="item in planFrom.planActionArray">
											<view style="float: left;">{{item.planName}}</view>
											<view style="float: right;color:red">删除</view>
											<view style="float: right;margin-right: 15rpx;color:#4089ff" @click="insertAction(item.fitnessPurposeId)">添加动作</view>
										</view> -->
						            </view>
								</u-popup>
			<view style="overflow: auto;height: 86vh;width: 100%;">
				<view style="width: 90%;padding: 40rpx;margin-top: -40rpx;">
				<!-- @tap="openTrain(item)" -->
				<view  style="float: right;width:100rpx;color:#fff;height: 50rpx; border-radius: 10rpx; background-image: linear-gradient(to bottom right, #94A9FD, #9ECFFF, #b9e1ff); display: flex; align-items: center; justify-content: center;">
				  <text style="letter-spacing: 4px;font-size: 24rpx;" @click="inserts">&nbsp;+新增</text>
				</view>
				</view>
				<view style="width: 90%;padding: 40rpx;" >
					<view  style="width: 85vw;background-color: #F7F7F7;margin: 0 auto;height: 180rpx;padding: 5px;box-sizing: border-box;margin-top: 10rpx;" v-for="(item, index) in planList" :key="index">
						<view style="font-size: 26rpx;float: left;width: 90%;padding: 20rpx">
							<view style="height: 35rpx;float: left;">
								<view style="display: flex;align-items: center;">第{{ index+1 }}组</view>
								<view style="margin-left: 30rpx;">
								<view style="display: flex;align-items: center;">动作次数：<span v-if="ben">{{item.actionCount}}</span><input v-if="kuang" @click="inputs(item)" @blur="submit(item)" type="text" v-model="item.actionCount" style="width: 20px; background-color: rgb(235, 234, 234);border-radius :20rpx;text-align: center;" >次</view>
								<view style="display: flex;align-items: center;margin-top: 20rpx;">器材重量：<span v-if="ben">{{item.equipmentWeight}}</span><input v-if="kuang" @click="inputs(item)"  @blur="submit(item)" type="text" v-model="item.equipmentWeight" style="width: 20px; background-color: rgb(235, 234, 234);border-radius :20rpx;text-align: center;" >kg</view></view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				item:{},
				insert:false,
				kuang:true,
				ben:false,
				messageText:'',
				title: 'picker',
				errTitle:'',
				selectedIndex:0,
				selectPlan:{},
				selectId:0,
				multiArray: [],
				index: 0,
				show: false,
				errShow:false,
				courseList: [
				],
				planList:[],
					current: 0,
					selectStatus:1,
					dayOfMonth: 0,
					daySelect: 0,
					today: '',
					msgType: 'sussess'
			}
		},
		onLoad(option) {
			this.item = JSON.parse(option.item) //打印出上个页面传递的参数。
			console.log(this.item )
			this.getReservation()
			this.getPlan()
			this.getAction()
		},
		methods: {
			inputs(item){
				console.log(item)
			},
			submits(){
				this.item.planActionId=this.item.id
				var ths=this
				uni.request({
					url: this.URL+'plan/addFitnessPlanActionCount',
					method: 'post',
					data: ths.item,
					// userInfo:res.
					success: function(res) {
						if(res.data.code==200){
							ths.getPlan()
						}else{
							
						}
					},
					fail: function(error) {
						// 处理请求失败
						console.error('删除失败');
					}
				})
			},
			open() {
			},
			close() {
				this.insert=false
			},
			inserts(){
				this.insert=true
			},
			submit(item){
				var ths=this
				uni.request({
					url: this.URL+'plan/updateFitnessPlanActionCount',
					method: 'put',
					data: item,
					// userInfo:res.
					success: function(res) {
						if(res.data.code==200){
							ths.getPlan()
						}else{
							
						}
					},
					fail: function(error) {
						// 处理请求失败
						console.error('删除失败');
					}
				})
			},
			update(item){
				this.kuang=true
				this.ben=false
			},
			del(item){
				var ths=this
				uni.request({
					url: this.URL+'plan/deleteFitnessPlanActionCount',
					method: 'delete',
					data: item,
					// userInfo:res.
					success: function(res) {
						if(res.data.code==200){
							
							ths.getPlan()
						}else{
							
						}
						
					},
					fail: function(error) {
						// 处理请求失败
						console.error('删除失败');
					}
				})
			},
			fan(){
				uni.$emit('pageRefresh');
				uni.navigateBack({
				        delta: 1 // 返回的页面数，这里是返回上一页，所以是1
				    });
			},
			getAction() {
				
			},
			selectUser(item){
				this.selectId=item.id
			},
			handleChange(event) {
				const selectedIndex = event.detail.value; // 获取选中的索引
				const selectPlan = this.planList[selectedIndex]; // 获取选中的对象数据
				var ths = this;
				uni.request({
					url: this.URL+'vipPlan/memberAddPlan',
					method: 'POST',
					data: {
						memberId: ths.selectId,
						seriesId: selectPlan.id
					},
					// userInfo:res.
					success: function(res) {
						if(res.data.code==200){
							this.getReservation()
							ths.show=true
							setTimeout(() => {
							        ths.show = false;
							      }, 2000);
						}else{
							ths.errShow=true
							ths.errTitle=res.data.data
							setTimeout(() => {
							        ths.errShow = false;
							      }, 2000);
						}
						
					},
					fail: function(error) {
						// 处理请求失败
						console.error('角色查询失败,请检查网络');
					}
				})
				
			},
			getReservation(){
				var ths = this;
				uni.request({
					url: this.URL+'AppCoach/getStudentByTeacherId',
					method: 'GET',
					data: {
						coachCode: uni.getStorageSync('teacherinfo').coachCode,
					},
					// userInfo:res.
					success: function(res) {
						ths.courseList = res.data.data;
					},
					fail: function(error) {
						// 处理请求失败
						console.error('角色查询失败,请检查网络');
					}
				})
			},
			getPlan(){
				var ths = this;
				uni.request({
					url: this.URL+'plan/getFitnessPlanActionCount',
					method: 'GET',
					data: {
						planActionId: this.item.id,
					},
					// userInfo:res.
					success: function(res) {
						ths.planList = res.data.data.content;
						console.log(ths.planList)
					},
					fail: function(error) {
						// 处理请求失败
						console.error('角色查询失败,请检查网络');
					}
				})
			},
			goSearch() {	
				
			},
			openTrain(item){
				uni.navigateTo({
					url: '/pages/coach/Reservation/Reservation?item='+JSON.stringify(item)
				})
			},
		}
	}
</script>

<style>
	.title {
			font-size: 14px;
			font-weight: bold;
			margin: 20px 0 5px 0;
		}
	.data-pickerview {
			height: 400px;
			border: 1px #e5e5e5 solid;
		}
	
		 .popper__arrow {
	    top: -6px;
	    left: 50%;
	    margin-right: 3px;
	    border-top-width: 0;
	    border-bottom-color: #EBEEF5;
	}
	 .popper__arrow {
	    top: -6px;
	    left: 50%;
	    margin-right: 3px;
	    border-top-width: 0;
	    border-bottom-color: #EBEEF5;
	}
	.week-item-d1{
		background-color: #9da4ff;
		width: 23px;height:23px;
		margin: 0 auto;
		border:#92A3FD;
		border-radius: 50%;
		margin-top: 1vh;
		font-size: 28rpx;
		padding-top: 2px;
		box-sizing: border-box;
		padding-right: 3rpx;
	}
	.div2{
		width: 100%;
		height: 5vh;
	}
	.div2-2{
		background-color:#fff;
		border-radius: 20px 20px;
		height: 70rpx;
		width: 90%;
		margin: 0 auto;
	}
/* ::v-deep .div2-2 .input-placeholder {
    color: #FFF;
} */
.week-display {
	display: flex;
	justify-content: space-between;
	color: #fff;
	width: 90%;
	height: 8vh;
	margin: 0 auto;
	margin-top: 2vh;
}

.week-item {
	flex: 1;
	text-align: center;
}

.back {
	position: relative;
	width: 100%;
	height: 100vh;
	overflow: hidden; /* 超出部分隐藏，可根据需求调整 */
}
.homeclick{
	height: 70rpx;
	width: 70rpx;
	margin-top: 20rpx;
}
.dao{
	 float: left;
	 width: 50%;
	 margin: 0 auto;
	 margin-top: 20rpx;
	 height: 45rpx;
	 font-size: 25rpx;
}
.dao-1{
	 border-bottom: skyblue 3px solid;
	 width: 30%;
	 margin: 0 auto;
	 height: 45rpx;
	 display: flex;
	 justify-content: center;
	 align-items: center;
}
.dao-2{
	 width: 30%;
	 margin: 0 auto;
	 height: 45rpx;
	 display: flex;
	 justify-content: center;
	 align-items: center;
}
.imagg{
	 width: 140rpx;
	 height: 140rpx;
	 border-radius: 4px;
}
</style>
